/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package backupit.core;

import backupit.core.FileInfoComparator;
import backupit.core.DefaultFileInfoComparator;
import java.util.Comparator;
import java.util.TreeSet;

/**
 * This class is responsible to handle FileInfos
 * @author dbotelho
 */
public class FileInfoSet extends TreeSet<FileInfo>{
    
    public FileInfoSet(){
        super(new DefaultFileInfoComparator(false));
    }
    
    /**
     * This constructer lets you define a new instance of FileInfoSet if some custom comparator.
     * @param comparator the comparator that will be used
     */
    public FileInfoSet(FileInfoComparator comparator){
        super(comparator);
    }
    
    /**
     * This method will try to find an specific file in this FileInfoSet, based on the comparator that it receives.
     * 
     * @param file The that's going to be used for searching
     * @param comparator the comparator that it will be used
     * @return true if the file exists
     */
    public boolean contains(FileInfo file, Comparator<FileInfo> comparator){
        for(FileInfo entry : this){
            if(comparator.compare(file, entry) == 0)
                return true;
        }
        return false;
    }

}
